
include $(PROJECT_ROOT)/gcc.mk

BUILD_DIR =output

OBJS+=$(addprefix $(BUILD_DIR)/, $(notdir $(SRC_C:.c=.o)))
OBJS+=$(addprefix $(BUILD_DIR)/, $(notdir $(SRC_S:.S=.o))) 
OBJS+=$(addprefix $(BUILD_DIR)/, $(notdir $(SRC_CPP:.cpp=.o)))

# CFLAGS+=-march=armv5te -mtune=arm926ej-s -mfloat-abi=soft -marm -mno-thumb-interwork -g -ggdb -Wall -fdata-sections -ffunction-sections -ffreestanding 
# CFLAGS+=-D__ARM32_ARCH__=5 -D__ARM926EJS__
# CFLAGS+=-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES=1 -DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES_HARD=1
# CFLAGS+=-fomit-frame-pointer -Wall -fverbose-asm -Os 
 
# DRAM size: 32M for F1C100s, 64M for F1C200s
# DRAM_SIZE = 64M

# LDFLAGS+=-Xlinker --gc-sections -Wl,--defsym=DRAM_SIZE=$(DRAM_SIZE),-Map=$(BUILD_DIR)/$(TARGET).map,--cref,--no-warn-mismatch

WARNINGS		:= -Wall -Wshadow -Wundef -Wmissing-prototypes -Wno-discarded-qualifiers -Wextra -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith \
					-fno-strict-aliasing -Wno-error=cpp -Wuninitialized -Wmaybe-uninitialized -Wno-unused-parameter -Wno-missing-field-initializers -Wtype-limits \
					-Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wformat-security \
					-Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body \
					-Wshift-negative-value -Wstack-usage=2048 -Wno-unused-value -std=gnu99
CFLAGS+ 			= -O3 -g0 $(WARNINGS)
LDFLAGS 		+= -lm



LIBS+=

ELF =$(BUILD_DIR)/$(TARGET)
# BIN =$(BUILD_DIR)/$(TARGET).bin
DIS =$(BUILD_DIR)/$(TARGET).dis
vpath %.c $(sort $(dir $(SRC_C)))
vpath %.S $(sort $(dir $(SRC_S)))
vpath %.cpp $(sort $(dir $(SRC_CPP)))
 

.PHONY : all clean test 

all: $(BUILD_DIR) $(OBJS) $(ELF)

$(BUILD_DIR):
	mkdir $@ 
 

$(BUILD_DIR)/%.o:%.c
	@echo CC .c $@  
	@$(CC) -c $(CFLAGS) $< $(INCLUDE) -o $@

$(BUILD_DIR)/%.o:%.cpp
	@echo CXX $@  
	@$(CXX) -c $(CFLAGS) $< $(INCLUDE) -o $@

$(BUILD_DIR)/%.o:%.S
	@echo AS $<
	@$(CC) $(CFLAGS) -c  $< $(INCLUDE) -o $@

$(ELF):$(OBJS)
	@echo linking $@
	@$(CC) $(LDFLAGS) $^ $(LIBS)   -o $@
	$(SZ) $@
 
dis: $(DIS)
#make 使用tools中的make工具，msys的make报错 'no such file'
$(DIS):$(ELF) 
	@echo objdump    
	$(OD) -D $< > $@


clean:
	rm -rf $(BUILD_DIR)


test :$(BUILD_DIR)
	@echo .c= $(SRC_C)  
	@echo .S=$(SRC_S)
	@echo inc=$(INCLUDE)
	@echo objs=$(OBJS)
	@echo cflgs=$(CFLAGS)
	@echo ld=$(LDCRIPT)
	@echo ldflag=$(LDFLAGS)

 
d:
	make clean
	make all -j12 
	make dis
 
	